<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                        <i class="fa  fa-fw fa-reorder"></i>账号权限管理
                        </li>
                    </ol>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <a class="btn btn-success" href="/admin_admin/add">新增账号</a>
                </div>
                <div class="col-md-6">
                    <form method="post" action="/admin_admin">
                        <div class="form-group input-group">
                        <input type="text" placeholder="请输入帐号关键字" value="<?=$pKey?>" name="key" class="form-control">
                        <span class="input-group-btn">
                          <button type="button" class="btn btn-default" id="search"><i class="fa fa-search"></i></button>
                        </span>
                        </div>
                    </form>
                </div>
            </div>

            <div class="panel-body text-center">
                <table class="table table-hover" id="sample-table-1">
                    <thead>
                        <tr>
                            <td>编号</td>
                            <td>账号</td>
                            <td>角色</td>
                            <td>总公司</td>
                            <td>所属公司</td>
                            <td>创建时间</td>
                            <td>状态</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <?foreach($tDatas as $tRow){?>
                    <tr>
                        <td><?=$tRow['id']?></td>
                        <td><?=$tRow['name']?></td>
                        <td><?
if($tRow['role'] == 'hd_admin'){
    echo "华道管理员";
}elseif($tRow['role'] == 'qy_admin'){
    echo "企业人资";
}elseif($tRow['role'] == 'bx_admin'){
    echo "保险公司";
}
?></td>
                            <td></td>
                        <td><?=$tRow['company']?></td>
                        <td><?=date('Y-m-d H:i:s',$tRow['created'])?></td>
                        <td><?=empty($tRow['status'])?'冻结':'正常'?></td>
                        <td>
                            <div class="visible-md visible-lg hidden-sm hidden-xs">
                            <a href="/admin_admin/edit?id=<?=$tRow['id']?>" class="btn btn-blue btn-xs tooltips" data-placement="top" data-original-title="编辑"><i class="fa fa-list"></i></a>
                            <a onclick="auth_manage(<?=$tRow['status']?>,'/admin_admin/auth?id=<?=$tRow['id']?>','/admin_admin')" href="javascript:void(0);" class="btn btn-red btn-xs tooltips" data-placement="top" data-original-title="<?=empty($tRow['status'])?"恢复":"冻结"?>"><i class="fa fa-key"></i></a>
                            <a href="#" onclick="cg_confirm_del('/admin_admin/del?id=<?=$tRow['id']?>','/admin_admin')" class="btn btn-orange btn-xs tooltips demo_4" data-placement="top" data-original-title="删除"><i class="fa fa-times"></i></a>
                            </div>
                            <div class="visible-xs visible-sm hidden-md hidden-lg">
                                <div class="btn-group">
                                    <a class="btn btn-green dropdown-toggle btn-sm" data-toggle="dropdown" href="#">
                                        <i class="fa fa-cog"></i> <span class="caret"></span>
                                    </a>
                                    <ul role="menu" class="dropdown-menu pull-right dropdown-dark">
                                        <li>
                                            <a role="menuitem" tabindex="-1" href="javascript:void(0);" onclick="auth_manage(<?=$tRow['status']?>,'/admin_admin/auth?id=<?=$tRow['id']?>','/admin_admin')">
                                                <i class="fa fa-key"></i><?=empty($tRow['status'])?"恢复":"冻结"?>
                                            </a>
                                        <li>
                                            <a role="menuitem" tabindex="-1" href="/admin_admin/edit?id=<?=$tRow['id']?>">
                                                <i class="fa fa-edit"></i>修改
                                            </a>
                                        </li>
                                        <li>
                                            <a role="menuitem" tabindex="-1" href="#" onclick="cg_confirm_del('/admin_admin/del?id=<?=$tRow['id']?>','/admin_admin')">
                                                <i class="fa fa-times"></i> 删除
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <?}?>
                </table>
                <?=$tShow?>
            </div>
        </div>
        <div class="subviews">
            <div class="subviews-container"></div>
        </div>
    </div>
    <!-- end: PAGE -->
</div>
<!-- end: MAIN CONTAINER -->
<script>
function auth_manage(pStatus,pAuthUrl,pJumpUrl){
    if(pStatus){
        var tTitle = "您确定要冻结该账号吗？";
        var tText = "冻结后该账号将无法登录后台";
    }else{
        var tTitle = "您确定要恢复该账号吗？";
        var tText = "恢复后该账号即可正常登录后台";
    }
    swal({
            title: tTitle,
            text: tText,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText:'确定',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },
        function(isConfirm){
            if(isConfirm){
                window.obj = '';
                $.ajax({
                    url: pAuthUrl,
                    data: 'status='+pStatus,
                    dataType: "json",
                    async:false,
                    success: function (obj) {
                        window.obj = obj;
                    }
                });

                if(window.obj.status == 1){
                    swal({title:"操作成功!", type:"success"},function(){
                        location.href = pJumpUrl;
                    });
                }else{
                    swal({title:window.obj.msg, type:"error"});
                }
            }
        }
    );
}
</script>
<script>
$('#search').click(function(){
    $('form').submit();
});
</script>
<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
